package com.shoppingmall.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.shoppingmall.R;

import androidx.appcompat.widget.AppCompatTextView;
import razerdp.basepopup.BasePopupWindow;

/**
 * 2020/3/7
 * 描述：提示性弹窗
 */
public class SuccessTipsDialog extends BasePopupWindow {

    private AppCompatTextView successTipTv;
    private AppCompatTextView confirmTv;
    private OnSureClickListener onSureClickListener;


    public SuccessTipsDialog(Context context) {
        super(context);
    }

    public SuccessTipsDialog(Context context, Builder builder) {
        this(context);
        setPopupGravity(Gravity.CENTER);
        setOutSideTouchable(false);
        bind(builder);

    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.dialog_success_tips);
    }

    private void bind(Builder builder) {
        successTipTv = findViewById(R.id.tv_success_tip);
        confirmTv = findViewById(R.id.tv_confirm);
        successTipTv.setText(builder.tipStr);
        confirmTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onSureClickListener)
                    onSureClickListener.confirm();
                dismiss();
            }
        });
    }

    public static class Builder {
        private Context context;
        private String tipStr;


        public Builder(Context context) {
            this.context = context;
        }

        public Builder setContent(String tipStr) {
            this.tipStr = tipStr;
            return this;
        }

        public SuccessTipsDialog build() {
            return new SuccessTipsDialog(context, this);
        }
    }

    public void setOnSureClickListener(OnSureClickListener onSureClickListener) {
        this.onSureClickListener = onSureClickListener;
    }

    public interface OnSureClickListener {
        void confirm();
    }
}
